<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

    <script th:inline="javascript">
        window.onload = function () {
            // 获取浏览器地址参数
            var params = new URLSearchParams(window.location.search);
            var codeValue = params.get('code');

            console.log(codeValue);

            let xxAppAddress = /*[[${xxAppAddress}]]*/ '';

            if (codeValue != null) {
                console.log("feishu login logic is effective");
                $.ajax({
                    url: "/feishu/auth",
                    method: "POST",
                    data: {
                        code: codeValue
                    },
                    success: function (response) {
                        // 请求成功后的处理逻辑
                        console.log("feishu auth response is ", response);

                        if (response) {
                            window.location.href = xxAppAddress + "/home";
                        } else {
                            let errorInfo = "登录报错，请联系系统管理员处理！";
                            console.error(errorInfo);
                            alert(errorInfo);
                        }
                    },
                    error: function (xhr, status, error) {
                        console.error("请求后端服务报错！", error);
                    }
            });
            } else {
                console.log("code is null, default login logic is effective");
                window.location.href = xxAppAddress + "/login";
            }
        };
    </script>
</head>
<body>
<div class="loading">
    <img src="/images/loading-1.png" alt="Loading...">
</div>
</body>
</html>